package com.smedi.ismedi.inmail.core.port.adapter.persistence.repository.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.MessageInfo;
import com.smedi.ismedi.inmail.core.domain.repository.MessageInfoRepository;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.model.MessageInfoEntity;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.mybatis.mapper.MessageInfoMapper;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author u
 */
@Repository
@AllArgsConstructor
public class MessageInfoRepositoryImpl extends ServiceImpl<MessageInfoMapper, MessageInfoEntity> implements MessageInfoRepository {
    private final DozerUtil dozerUtil;

    @Override
    public List<MessageInfo> doInsertList(List<MessageInfo> messageInfos) {
        List<MessageInfoEntity> messageInfoEntities = dozerUtil.convertor(messageInfos, MessageInfoEntity.class);
        for(MessageInfoEntity messageInfoEntity:messageInfoEntities){
            messageInfoEntity.setPushTime(LocalDateTime.now());
        }

        saveBatch(messageInfoEntities);
        return dozerUtil.convertor(messageInfoEntities, MessageInfo.class);

    }
}